package cn.kgc.mes.storage.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;

import cn.kgc.mes.common.core.plus.response.Result;
import cn.kgc.mes.common.core.plus.response.ResultUtil;
import cn.kgc.mes.common.core.plus.dto.common.CommonDataPageResponse;
import cn.kgc.mes.common.core.plus.response.StatusResponse;

import cn.kgc.mes.storage.domain.vo.WmItemRecptLineVo;
import cn.kgc.mes.storage.business.WmItemRecptLineBusiness;

/**
 * 物料入库单行控制器
 * 
 * @author cly
 * @date 2025-09-15
 */
@RestController
@RequestMapping("/line/line")
public class WmItemRecptLineController {

    @Resource
    WmItemRecptLineBusiness business;

    /**
     * 分页查询物料入库单行列表,根据入库单ID查询
     */
//    @PreAuthorize("@ss.hasPermi('line:line:list')")
    @GetMapping("/pageItemRecptLine")
    public Result page(@RequestParam("itemRecptId") Integer itemRecptId) {
        //转成Long类型
        Long itemRecptId2 = Long.valueOf(itemRecptId);
        // 创建查询参数对象
        WmItemRecptLineVo vo = new WmItemRecptLineVo();
        // 设置查询条件：recpt_id等于传入的itemRecptId
        vo.setRecptId(itemRecptId2);

        CommonDataPageResponse<WmItemRecptLineVo> response = business.page(vo);
        return ResultUtil.success(response);
    }

    /**
     * 获取物料入库单行详细信息
     */
//    @PreAuthorize("@ss.hasPermi('line:line:query')")
    @PostMapping("/infoItemRecptLine")
    public Result info(@RequestBody WmItemRecptLineVo vo) {

        WmItemRecptLineVo info = business.info(vo);

        return ResultUtil.success(info);
    }

    /**
     * 新增物料入库单行
     */
//    @PreAuthorize("@ss.hasPermi('line:line:add')")
    @PostMapping("/addItemRecptLine")
    public Result add(@RequestBody WmItemRecptLineVo vo) {

        StatusResponse response = business.add(vo);
        if (response.getSuccess() == false) {
            return ResultUtil.fail(response.getMsg());
        }

        return ResultUtil.success(response);
    }

    /**
     * 修改物料入库单行
     */
//    @PreAuthorize("@ss.hasPermi('line:line:edit')")
    @PostMapping("/updateRecptLine")
    public Result update(@RequestBody WmItemRecptLineVo vo) {

        StatusResponse response = business.update(vo);
        if (response.getSuccess() == false) {
            return ResultUtil.fail(response.getMsg());
        }

        return ResultUtil.success(response);
    }

    /**
     * 删除物料入库单行
     */
//    @PreAuthorize("@ss.hasPermi('line:line:remove')")
    @PostMapping("/deleteItemRecptLine")
    public Result delete(@RequestBody WmItemRecptLineVo vo) {

        StatusResponse response = business.delete(vo);
        if (response.getSuccess() == false) {
            return ResultUtil.fail(response.getMsg());
        }

        return ResultUtil.success(response);
    }

}
